// pages/goods/goods.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id: null,
    currentTab: 0,
    keyword: '',
    items: [
      {
        title: '选项卡1111',
        value: '1111'
      },
      {
        title: '选项卡2222',
        value: '2222'
      },
      {
        title: '选项卡3333',
        value: '3333'
      },
    ],
    videoUrl:
      'https://1897486322.hiecheimaetu.com:9218/qn-wAk9xJbTYKSZLNho5DWYuMVYtWjsUJSk2XG0aLw4.vodkgeyttp8.vod.126.net/cloudmusic/obj/core/4900900763/3cd17fd90115b222d86165f650fc7ee6.mp4?wsSecret=6695daca3bd6d4e37db789875bf2a6e9&wsTime=1713423765',
    videoContext: null,
    danmuList: [
      {
        text: '视频播放成功！',
        color: 'red',
        time: 1
      },
      {
        text: '不能发布违规信息',
        color: 'red',
        time: 20
      }
    ],
    danmuInputValue: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad({ id }) {
    this.setData({ currentTab: id })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.data.videoContext = wx.createVideoContext('video', this)
  },

  switchNav: function (e) {
    if (this.data.currentTab == e.target.dataset.current) {
      return false
    } else {
      this.setData({ currentTab: e.target.dataset.current })
    }
  },

  onSearchGoodsConfirm(e) {
    // TODO: 跳转到京东小程序首页
    // wx91d27dbf599dff74

    wx.navigateToMiniProgram({
      appId: 'wx91d27dbf599dff74'
    })

    this.setData({ keyword: '' })
  },

  onSendVideoDunmu() {
    const danmu = {
      text: this.data.danmuInputValue,
      color: this.getRandomColor()
    }
    this.data.videoContext.sendDanmu(danmu)
    this.data.danmuList.push({ ...danmu, time: 1 })

    this.setData({ danmuInputValue: '' })
  },

  onChangeDanmuInputValue(e) {
    this.setData({ danmuInputValue: e.detail.value })
  },

  getRandomColor() {
    return `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(
      Math.random() * 256
    )})`
  },

  hhhhh(msg,m) {
    console.log(m);
  }
})
